/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
// import {Navigator} from 'react-native';
import {Navigator} from 'react-native-deprecated-custom-components';
import Common from './common';


// export default class NavigatorSelf = StackNavigator({
//   Home: { screen: this.props.component },
// });

export default class NavigatorSelf extends Component {
  constructor(props) {
    super(props);
  }
  render() {
    return (
      <Navigator
        initialRoute={{ component:this.props.component, passProps:{name: this.props.name},index: 0 }}
        configureScene={(route, routeStack) => {
          
          return({
            ...Navigator.SceneConfigs.HorizontalSwipeJump,
            gestures: Navigator.SceneConfigs.PushFromRight.gestures
          })
        }}
        ref="navigator"
        onDidFocus={(route) => {
          let nav = this.refs.navigator;
          if(nav){
            let routeArr=nav.getCurrentRoutes();
            let routeLength=routeArr.length-1;
            if(routeArr.length>4){
              // let routArr_3= routeArr[3];
              // let newRoute=route;
              // routeArr.splice(3,1);
              // nav.immediatelyResetRouteStack(routeArr);
              // nav.replaceAtIndex(routArr_3,2);
              
              if(routeArr[routeLength].passProps.sameLevel =="true" && routeArr[routeLength-1].passProps.sameLevel =="true" && routeArr[routeLength-2].passProps.sameLevel =="true"){
                let routArr_3= routeArr[routeLength-1];
                routeArr.splice(routeLength-1,1);
                nav.immediatelyResetRouteStack(routeArr);
                nav.replaceAtIndex(routArr_3,routeLength-2);

              }

            }
          }
          
        }}
        renderScene={(route, navigator) =>
          <route.component navigator={navigator}  {...route.passProps} />
        }/>
    );
  }
}